﻿using MaterialDesignColors;
using MaterialDesignColors.ColorManipulation;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using 基于WPF的电缆采样数据分析系统.Tools.LangugeTool;
using 基于WPF的电缆采样数据分析系统.Tools.MessagePopupTool;

namespace 基于WPF的电缆采样数据分析系统.ViewModels.Settings
{
    public class PersonalUCViewModel : BindableBase
    {
        #region 主题背景
        /// <summary>
        /// 主题背景属性
        /// </summary>
        private bool _isDarkTheme;

        /// <summary>
        /// 主题背景属性
        /// </summary>
        public bool IsDarkTheme
        {
            get => _isDarkTheme;
            set
            {
                if (SetProperty(ref _isDarkTheme, value))
                {
                    ModifyTheme(theme => theme.SetBaseTheme(value ? Theme.Dark : Theme.Light));
                }
            }
        }

        /// <summary>
        /// 根据主题背景属性切换软件样式背景
        /// </summary>
        /// <param name="modificationAction"></param>
        private static void ModifyTheme(Action<ITheme> modificationAction)
        {
            var paletteHelper = new PaletteHelper();
            ITheme theme = paletteHelper.GetTheme();

            modificationAction?.Invoke(theme);

            paletteHelper.SetTheme(theme);
        }

        #endregion


        #region 顶部背景颜色

        /// <summary>
        /// 调色器助手
        /// </summary>
        private readonly PaletteHelper paletteHelper = new PaletteHelper();

        /// <summary>
        /// 色板
        /// </summary>
        public IEnumerable<ISwatch> Swatches { get; } = SwatchHelper.Swatches;

        /// <summary>
        /// 改变当前色调命令
        /// </summary>
        public DelegateCommand<object> ChangeHueCommand { get; set; }

        /// <summary>
        /// 改变色调
        /// </summary>
        /// <param name="obj"></param>
        private void ChangeHue(object obj)
        {
            ITheme theme = paletteHelper.GetTheme();

            var color = (Color)obj;
            theme.PrimaryLight = new ColorPair(color.Lighten());
            theme.PrimaryMid = new ColorPair(color);
            theme.PrimaryDark = new ColorPair(color.Darken());

            paletteHelper.SetTheme(theme);

            // 消息提示
            MessagePopup.DisplayMessagePopup(LangugeConvertor.GetValue("SubjectChange"));
        }

        #endregion

        /// <summary>
        /// 构造器
        /// </summary>
        PersonalUCViewModel()
        {
            // 绑定改变当前色调命令
            ChangeHueCommand = new DelegateCommand<object>(ChangeHue);

            // 主题背景属性默认为深色
            IsDarkTheme = true;
        }
    }
}
